/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package parse;

import drt.DrtExpression;
import java.util.LinkedList;
import java.util.List;
import learn.LexicalEntry;
import learn.LexicalSurface;

/**
 *
 * @author phong
 */
public class CCGLexNode extends CCGNode {

    LexicalSurface surf;
    
    public CCGLexNode(LexicalSurface surf, DrtExpression sem, int tokId) {
        super(surf.getCat(), sem);
        this.surf = surf;        
        this.tokEndId = this.tokStartId = tokId;
    }
    
    public CCGLexNode(LexicalSurface surf, DrtExpression sem, int tokId, double prob) {
        this(surf, sem, tokId);
        this.prob = prob;
    }
    
    public LexicalSurface getLexSurface() {
        return this.surf;
    }
    
    public LexicalEntry getLexEntry() {
        return new LexicalEntry(surf, sem);
    }
    
    @Override
    public List<CCGLexNode> getLexNodes() {
        List<CCGLexNode> lexNodes = new LinkedList<CCGLexNode>();
        lexNodes.add(this);
        return lexNodes;
    }
    
        
    public String getPos() {
        return this.surf.getPos();
    }
    
    public String getNe() {
        return this.surf.getNe();
    }
    
    @Override
    public CCGNode[] getChildren() {
        return new CCGNode[0];
    }
    
    @Override
    public void updateTokIDs() {
    }
    
    @Override
    public String toString() {
        StringBuffer buffTabs = new StringBuffer();        
        for (int i = 0; i < tabs; i++) 
            buffTabs.append("\t");
        String strTabs = buffTabs.toString();
        
        StringBuffer buff = new StringBuffer();
        
        buff.append(strTabs).append("<lex>").append("\n");
        buff.append(strTabs).append(this.getPos()).append("\n");
        buff.append(strTabs).append(this.getNe()).append("\n");
        buff.append(strTabs).append(this.cat).append("\n");
        buff.append(strTabs).append(this.sem).append("\n");
        buff.append(strTabs).append(this.tokStartId).append("\n");
                
        return buff.toString();
    }
    
    @Override
    public void updateSem() {
    }
    
    @Override
    public void putInChart(Chart chart) {
        Cell cell = chart.getCell(this.tokStartId, this.tokEndId);
        cell.add(this);
    }
    
    @Override
    public boolean equals(Object o) {
        if (o instanceof CCGLexNode) {
            CCGLexNode that = (CCGLexNode)o;
            return this.surf.equals(that.surf) && this.sem.equals(that.sem);
        }
        else 
            return false;
    }
    
    @Override
    public int hashCode() {
        return this.surf.hashCode() * 17 + this.sem.hashCode();
    }
}
